package com.zhaolixiang.slidetabview;

import android.content.Context;
import android.graphics.Point;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class ForScreen {
	/**
	 * 获取屏幕宽度
	 * @return
	 */
	public static int getWindowsWidth(Context context){
		//之前方法
       /* WindowManager windowManager= (WindowManager) MyApplication.getInstance().getSystemService(Context.WINDOW_SERVICE);
        return  windowManager.getDefaultDisplay().getWidth();*/
		DisplayMetrics displayMetrics=new DisplayMetrics();
		WindowManager windowManager= (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		windowManager.getDefaultDisplay().getMetrics(displayMetrics);
		//返回px
		return displayMetrics.widthPixels;

	}
	/**
	 * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
	 */
	public static int dip2px(Context context, float dpValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (dpValue * scale + 0.5f);
	}
	public static int sp2px(Context context, float spValue) {
		final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
		return (int) (spValue * fontScale + 0.5f);
	}

	public static float sp2pxReturnFloadt(Context context, float spValue) {
		final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
		return  (spValue * fontScale + 0.5f);
	}
}
